/*
* $Id: ChangePointOperation.cpp 154 2010-09-27 08:10:48Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "ChangePointOperation.h"
#include "../Tables/PointsTable.h"
#include "FieldValuesOperation.h"
#include "Event/EventId.h"

CChangePointOperation::CChangePointOperation(){}
CChangePointOperation::~CChangePointOperation(){}

CChangePointOperation::content::content(){
	Clear();
}
void CChangePointOperation::content::Clear(){
	s_nId = 0;
	s_strName.clear();
	s_strNote.clear();
	s_nIdRecord = 0;
	s_aUserFields.clear();
}

void CChangePointOperation::UpdateValue(IDatabase* pDatabase){
	CPointsTable points;
	points.m_content.s_nId = m_content.s_nId;
	IResult* pResult = points.GetValue(pDatabase);
	int nIdRecord = 0;
	if(pResult->GetSizeResult())
		nIdRecord = ((CPointsTable::content*)(*pResult)[0])->s_nIdRecord;
	pResult->Free();
	CFieldValuesOperation fieldValues;
	fieldValues.m_content.s_nId = nIdRecord;
	fieldValues.m_content.s_table = TypeField::POINTS;
	fieldValues.m_content.s_aUserFields = m_content.s_aUserFields;
	fieldValues.UpdateValue(pDatabase);
	nIdRecord = fieldValues.m_content.s_nId;
	points.m_content.s_nIdRecord = nIdRecord;
	points.m_content.s_nId = m_content.s_nId;
	points.m_content.s_strName = m_content.s_strName;
	points.m_content.s_strNote = m_content.s_strNote;
	points.UpdateValue(pDatabase);
	m_content.s_nIdRecord = nIdRecord;
	IEventManager::GetEventManager()->SendEvent(POINTS_DB_CHANGE_EVENT);
}